import {Module} from '@nestjs/common';
import {UserModule} from './user/user.module';
import {PrismaModule} from '../prisma/prisma.module';
import {ThrottlerGuard, ThrottlerModule} from '@nestjs/throttler';
import {APP_GUARD} from '@nestjs/core';
import {AuthModule} from './auth/auth.module';
import {RedisModule} from '@nestjs-modules/ioredis';
import {UtilsModule} from './utils/utils.module';
import {JwtAuthGuard} from './guard/jwt-auth.guard';
import {FriendModule} from "./friend/friend.module";
import {UploadModule} from "./upload/upload.module";
import { SocketModule } from './socket/socket.module';

@Module({
    imports: [
        RedisModule.forRoot({
            type: 'single',
            url: 'redis://localhost:6379',
        }),
        ThrottlerModule.forRoot({
            throttlers: [
                {
                    ttl: 60, // 时间窗口，秒
                    limit: 10, // 请求次数限制
                },
            ],
            errorMessage: '请求过于频繁，请稍后再试。',
        }),
        PrismaModule,
        UserModule,
        AuthModule,
        UtilsModule,
        FriendModule,
        UploadModule,
        SocketModule
    ],
    providers: [
        {
            provide: APP_GUARD,
            useClass: JwtAuthGuard,
        },
        {
            provide: APP_GUARD,
            useClass: ThrottlerGuard,
        },
    ],
})
export class AppModule {
}
